package marksys.free.com.marksys.nettool;

import android.arch.lifecycle.LiveData;

import java.util.List;

import marksys.free.com.marksys.nettool.common.Resource;
import marksys.free.com.marksys.nettool.common.ResourceConvertUtils;
import marksys.free.com.marksys.nettool.retrofit.RetrofitUtils;
import marksys.free.com.marksys.nettool.vo.Cause;
import marksys.free.com.marksys.nettool.vo.Detail;
import marksys.free.com.marksys.nettool.vo.Grades;
import marksys.free.com.marksys.nettool.vo.History;
import marksys.free.com.marksys.nettool.vo.Projects;
import marksys.free.com.marksys.nettool.vo.Photo;
import marksys.free.com.marksys.nettool.vo.Today;
import marksys.free.com.marksys.nettool.vo.User;
import okhttp3.MultipartBody;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Query;


/**
 * Created by zlinsun on 2018/7/31.
 * hah
 */
public class MyApi {
    public interface ApiService {

        @POST("cater/patchMeal")
        LiveData<ApiResult<String>> patchMeal(@Query("eatToken") String eatToken, @Query("cardNumber") String cardNumber);

        @POST("api/moral/login.do")
        LiveData<ApiResult<User>> login(@Query("loginName") String loginName, @Query("password") String password);

        @Multipart
        @POST("api/moral/upload.do")
        LiveData<ApiResult<List<Photo>>> upload(@Part() List<MultipartBody.Part> file);

        @GET("api/moral/projects.do")
        LiveData<ApiResult<List<Projects>>> projects(@Query("type") int type);

        @GET("api/moral/reasons.do")
        LiveData<ApiResult<List<Cause>>> cause(@Query("id") long id);

        @GET("api/moral/grades.do")
        LiveData<ApiResult<List<Grades>>> grades();

        @FormUrlEncoded
        @POST("api/moral/push.do")
        LiveData<ApiResult<Object>> push(@Query("project") long project, @Query("classId") long classId, @Query("reason") long reason,
                                         @Query("sorce") double sorce, @Query("images") String images, @Query("video") String video, @Field("content") String content);

        @GET("api/moral/detail.do")
        LiveData<ApiResult<Detail>> detail(@Query("id") long id);

        @POST("api/moral/cancel.do")
        LiveData<ApiResult<Object>> delete(@Query("id") long id);

        @GET("api/moral/history.do")
        LiveData<ApiResult<History>> history(@Query("type") int type, @Query("page") int page, @Query("pagesize") int pagesize);

        @FormUrlEncoded
        @POST("api/moral/modify.do")
        LiveData<ApiResult<Object>> modify(@Query("id") long id, @Query("project") long project, @Query("classId") long classId, @Query("reason") long reason,
                                           @Query("sorce") double sorce, @Query("images") String images, @Query("video") String video, @Field("content") String content);

        @GET("api/moral/today.do")
        LiveData<ApiResult<Today>> today(@Query("classId") long classId);

    }

    public static LiveData<ApiResult<String>> patchMeal(String eatToken, String cardNumber) {

        return RetrofitUtils.getInstance().apiService.patchMeal(eatToken, cardNumber);
    }

    public static LiveData<Resource<User>> login(String loginName, String password) {
        return ResourceConvertUtils.convertToResource(RetrofitUtils.getInstance().apiService.login(loginName, password));
    }

    public static LiveData<Resource<List<Photo>>> upload(List<MultipartBody.Part> file) {
        return ResourceConvertUtils.convertToResource(RetrofitUtils.getInstance().apiService.upload(file));
    }

    public static LiveData<Resource<List<Projects>>> projects(int type) {
        return ResourceConvertUtils.convertToResource(RetrofitUtils.getInstance().apiService.projects(type));
    }

    public static LiveData<Resource<List<Cause>>> cause(long id) {
        return ResourceConvertUtils.convertToResource(RetrofitUtils.getInstance().apiService.cause(id));
    }

    public static LiveData<Resource<List<Grades>>> grades() {
        return ResourceConvertUtils.convertToResource(RetrofitUtils.getInstance().apiService.grades());
    }

    public static LiveData<Resource<Object>> push(long project, long classId, long reason, double sorce, String images, String video, String content) {
        return ResourceConvertUtils.convertToResource(RetrofitUtils.getInstance().apiService.push(project, classId, reason, sorce, images, video, content));
    }

    public static LiveData<Resource<Detail>> detail(long id) {
        return ResourceConvertUtils.convertToResource(RetrofitUtils.getInstance().apiService.detail(id));
    }

    public static LiveData<Resource<Object>> delete(long id) {
        return ResourceConvertUtils.convertToResource(RetrofitUtils.getInstance().apiService.delete(id));
    }

    public static LiveData<Resource<Object>> modify(long id, long project, long classId, long reason, double sorce, String images, String video, String content) {
        return ResourceConvertUtils.convertToResource(RetrofitUtils.getInstance().apiService.modify(id, project, classId, reason, sorce, images, video, content));
    }

    public static LiveData<Resource<Today>> today(long classId) {
        return ResourceConvertUtils.convertToResource(RetrofitUtils.getInstance().apiService.today(classId));
    }
}
